
import {defineStore} from "pinia";

export const useMockStore = defineStore('mock', {
    state: () => ({
        isMockEnabled: true,
        users: [],
        cases: [],
    }),
    actions: {
        toggleMock() {

        },
        setCases(cases) {
            this.cases = cases;
        },
        setUsers(users) {
            this.users = users;
        },
        addUser(user) {
            this.users.push(user);
        },
        updateUser(updatedUser) {
            const index = this.users.findIndex(user => user.id === updatedUser.id);
            if (index !== -1) {
                this.users[index] = updatedUser;
            }
        },
        deleteUser(userId) {
            this.users = this.users.filter(user => user.id !== userId);
        },
        clearUsers() {
            this.users = [];
        },
        getUserById(userId) {
            return this.users.find(user => user.id === userId);
        },
        findByUsername(username) {
            console.log('findByUsername:',username);
            return this.users.find(user => user.username === username);
        }
    }
})